# -*- coding: utf-8 -*-

"""
@Datetime: 2019/2/9
@Author: Zhang Yafei
"""
from __future__ import division
from flask import render_template, g, request, Markup, current_app
import datetime


def active_path(path):
    req_path = request.path.split('/')
    if req_path[1] == path.split('/')[1]:
        node = '<li class="active">'
    else:
        node = '<li>'
    return Markup(node)


def get_obj_attr(obj, column):
    val = getattr(obj, column)
    return val


def get_form_field_error(form, field):
    return getattr(getattr(form, field), 'errors')[0]


def ops_render(template, context=dict()):
    '''统一渲染方法'''
    context['menus'] = current_app.config.get('MENUS')
    if 'current_user' in g:
        context['current_user'] = g.current_user
    return render_template(template, **context)


def getCurrentDate(format='%Y-%m-%d %H:%M:%S'):
    """获取当前时间"""
    # return datetime.datetime.now()
    return datetime.datetime.now().strftime(format)

